<include file=".:Common:header" />
<script language="javascript">
$(function(){
	$('form').form({ 
		success:function(data){
			var data = runJson(data);
			if(data.status == 0){
				alertText(data.info, 'error');
			}else{
				alertText(data.info, 'success', '{:U('Role/index')}');
			}
		}   
	}); 
}); 
function clearPurview(){
	$('#formDiv').find('input').attr('checked', false);
}
function resetPurview(){
	document.getElementById('formDiv').reset();
}
</script>
<div class="wrapper clear">
	<div class="main">
		<div class="toolbar">
			<a href="javascript:resetPurview();" id="addnewitem">重置权限</a>
			<a href="javascript:clearPurview()" id="remove">清空权限</a>
		</div>
		<div class="search">
            <div class="searchbox">
<style type="text/css">
#LD a, #LD a:visited { color:#003264}
.list-div table th span { height:30px; line-height:30px; border-right:1px solid #BBDDE5; display:block; background:none; float:left; padding:0px 10px; overflow:hidden; cursor:pointer}
.list-div table tr { background:#FFFFFF;}
.list-div table th .cur { background:#F4FAFF; }
.list-div label { line-height:25px; margin-right:10px; }
.ur_heres { height:35px; padding-left:20px; line-height:35px; overflow:hidden; font-size:14px; font-weight:bold; background:#F4FAFF}
.p { width:170px; height:25px; line-height:25px; text-align:left; float:left; overflow:hidden; display:block;}
.list-div table {
	border:1px;
}
.list-div table td {
	height:24px;
	line-height: 24px;
	padding-left:5px;
	text-align:left;
	border-right:1px dotted #ccc;
	border-bottom:1px dotted #ccc;
	white-space:nowrap;

}
.list-div td.first-cell{
  font-weight: bold;
  padding-left: 5px;
}
</style>
<form action="{:U('Role/topurview')}&ajax=true" id="formDiv" method="post">
  <div class="formd" style="overflow:hidden; line-height:30px; ">
   <span style="float:right;"><label for="all"><input type="checkbox" name="all" id="all" value="all" <php> if($isAll=='all'){ echo 'checked'; }</php>/>超级管理员权限</label></span>角色名称：<b>{$info.name}</b>
  </div>
 
  <div class="easyui-tabs">
	<?php foreach($myMainMenu as $app=>$row): ?>
    <div title="<?php echo $row['name'];?>" class="list-div">
    	<table width="100%" border="0" cellspacing="1" cellpadding="1" id="LD">
          <tr>
            <td class="label" width="15%">&nbsp;</td>
            <td>
            <label for="showm_<?php echo $app;?>"><input <?php if(isset($hasPurview[$app][all])): echo 'checked'; endif;?> type="checkbox" value="on" name="purview[<?php echo $app; ?>][all]" id="showm_<?php echo $app;?>" />该应用全部权限</label>
            <label for="label_<?php echo $app.$row['module'].$row['action']; ?>"><input <?php if(isset($hasPurview[$app][$row['module']][$row['action']])): echo 'checked'; endif;?> type="checkbox" name="purview[<?php echo $app; ?>][<?php echo $row['module'];?>][<?php echo $row['action'];?>]" value="on" id="label_<?php echo $app.$row['module'].$row['action']; ?>" />显示主菜单</label>
            </td>
          </tr>
          <?php foreach($row['items'] as $k=>$item): ?>
          <tr>
            <td><?php echo $item['name'];?>：</td>
            <td>
            <label for="label_showall<?php echo $app.$item['module'].$item['action']; ?>"><input <?php if(isset($hasPurview[$app][$item['module']][all])): echo 'checked'; endif;?> type="checkbox" name="purview[<?php echo $app; ?>][<?php echo $item['module']; ?>][all]" value="on" id="label_showall<?php echo $app.$item['module'].$item['action']; ?>"/>该模块全部权限</label>
            <br />
            <label for="label_<?php echo $app.$item['module'].$item['action']; ?>"><input <?php if(isset($hasPurview[$app][$item['module']][$item['action']])): echo 'checked'; endif;?> type="checkbox" name="purview[<?php echo $app; ?>][<?php echo $item['module']; ?>][<?php echo $item['action']; ?>]" value="on" id="label_<?php echo $app.$item['module'].$item['action']; ?>" />查看默认页</label>
            <?php if(!empty($item['rbacs'])): ?>
            <?php foreach($item['rbacs'] as $tk=>$v): ?>
            <label for="label_<?php echo $app.$item['module'].$tk; ?>"><input <?php if(isset($hasPurview[$app][$item['module']][$tk])): echo 'checked'; endif;?> type="checkbox" name="purview[<?php echo $app; ?>][<?php echo $item['module']; ?>][<?php echo $tk;?>]"  value="on"id="label_<?php echo $app.$item['module'].$tk; ?>" /><?php echo $v; ?></label>
            <?php endforeach; ?>
            <?php endif; ?>
            </td>
          </tr>
          <?php endforeach; ?>
        </table>
    </div>
    <?php endforeach; ?>
  </div>
    <div class="form-div" style="text-align:center; margin-top:10px;">
    <input type="hidden" name="id" value="{$info.id}" />
    <input style="height:30px" type="submit" value="保存设置" class="submit" onclick="return $('form').form('validate');"/>
    <input style="height:30px" type="reset" value="重置" class="cancel"/>
  </div>
		</div>
   </foreach>
	</div>
    
</form>          
            
            
            </div>
		</div>
	</div>
</div>	            
<script language="javascript">
$(function(){
	$("#LD tr").hover(
		function(){
		$(this).css({background:"#f9f9f9"});
		},
		function(){
		$(this).css({background:"#ffffff"});
		}
	);
	$("#all").click(function(){
		if($("#all").attr("checked")){
			$("#moduleDIV").hide();
		}else{
			$("#moduleDIV").show();
		}
	});
	$("#clearAll").click(function(){
		$("input[name^='purview']").each(function(){
			$(this).attr("checked", false);
		});
	});
});
//选择下级所有模块
function selectPur(idp){
	if($("#"+idp+"all").attr("checked")){
		$("input[id^='"+idp+"'][name^='purview']").each(function(){
			$(this).attr("checked", true);
		});
	}else{
		$("input[id^='"+idp+"'][name^='purview']").each(function(){
			$(this).attr("checked", false);
		});
	}
	checkMainPur();
}
function checkPur(idp){
	var is_checked = $("#"+idp+"all");
	var is_checked_show = $("#"+idp+"showmenu");
	var to_checked = true;
	var to_checked_show = false;
	$("input[id^='"+idp+"'][name^='purview']").each(function(){
		if(!$(this).attr("checked") && $(this).attr("id") != is_checked.attr("id")){
			to_checked = false;
		}
		if($(this).attr("checked") && $(this).attr("id") != is_checked_show.attr("id")){
			to_checked_show = true;
		}
	});
	if(is_checked){
		if(to_checked){
			$("#"+idp+"all").attr("checked", true);
		}else $("#"+idp+"all").attr("checked", false);
	}else{
		if(!to_checked){
			$("#"+idp+"all").attr("checked", true);
		}else $("#"+idp+"all").attr("checked", false);
	}
	if(to_checked_show){
		$("#"+idp+"showmenu").attr("checked", true);
	}else $("#"+idp+"showmenu").attr("checked", false);
	//选择主菜单项
	checkMainPur();
}

function checkMainPur(){
	var to_check_main = false;
	$("#table_"+span+" input").each(function(){
		if($(this).attr("checked") && $(this).attr("id") != $("#main_"+span).attr("id")){
			to_check_main = true;
		}
	});
	if(to_check_main){
		$("#main_"+span).attr("checked", true);
	}else{
		$("#main_"+span).attr("checked", false);
	}
}
</script>
<include file=".:Common:footer" />